package com.aaa.demo112.demo2;

import java.util.concurrent.*;

/**
 * @Description:
 * @author:LiWei
 * @date:2022年11月02日10:32
 */
public class Test {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable my=new MyCallable();

        FutureTask task = new FutureTask(my);
        Thread t=new Thread(task);
        t.start();
        System.out.println(task.get());

        ExecutorService executorService= Executors.newFixedThreadPool(2);
        Future<Integer>future=executorService.submit(new MyCallable());
        executorService.shutdown();
        System.out.println(future.get());

    }
}
class MyCallable implements Callable<Integer>{

    @Override
    public Integer call() throws Exception {
        int sum=0;
        for (int i = 0; i < 100; i++) {
            sum+=1;
        }
        return sum;
    }
}